package com.ohuang.test_compose.page

import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import com.ohuang.test_compose.ui.theme.Test_composeTheme

@Composable
fun RecombinationScopePage() {
    Test_composeTheme {
        Column {
            ReChangePage()
        }
    }
}

@Composable
fun ReChangePage() {
    Column {

        Text(text = "")
        var sate by remember {
            mutableStateOf("123")
        }
        Button(onClick = { sate = "" + System.currentTimeMillis() }) {
            Text(text = "点击重组1")
        }
        Text(text = sate, color = getRandomColor())
        Text(text = "共享compose作用域  会发生重组", color = getRandomColor())
        AA()
        BB(sate) {
            Text(text = "lambda作用域,也是一个独享作用域 ", color = getRandomColor())
        }
        BB("123") {
            Text(text = "lambda作用域,也是一个独享作用域 $sate", color = getRandomColor())
        }
        CC(sate, "123")
    }
}

@Composable
fun CC(text: String, bb: String) {
    Text(text = "若作用域内没有用到改变的参数 不发生重组:$bb  ", color = getRandomColor())
}





@Composable
fun BB(text: String, content: (@Composable () -> Unit)) {
    Text(text = "bb:" + text, color = getRandomColor())
    content()
}

@Composable
fun AA() {
    Text(text = "独享compose作用域  不发生重组", color = getRandomColor())
}